package com.example.controller;


import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.common.result.Result;
import com.example.entity.dto.KeepRecordPageDto;
import com.example.entity.vo.KeepRecordVo;
import com.example.exception.BaseException;
import com.example.service.KeepRecordService;
import com.example.service.KeepResService;
import com.github.pagehelper.Page;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/keeprecord")
@DS("mes")
@Api(tags = "保养记录相关",position = 996)
public class KeepRecordController {
    @Autowired
    private KeepRecordService keepRecordService;
    @Autowired
    private KeepResService keepResService;
    @GetMapping("/page")
    @ApiOperation("分页保养记录")
    public Result<Page<KeepRecordVo>> pageKeepRecord(KeepRecordPageDto recordPageDto){
        Page<KeepRecordVo> keepRecordVoPage=keepRecordService.pageRecord(recordPageDto);
        return Result.success(keepRecordVoPage);
    }

    @DeleteMapping("/delete")
    @ApiOperation("批量删除保养记录")
    public Result deleteKeepRecord(@RequestBody List<Integer> ids){
        keepResService.removeBatchByRecordIds(ids);
        boolean b = keepRecordService.removeByIds(ids);
        if (!b)throw new BaseException("删除保养记录失败！保养记录不存在或已删除！");
        return Result.success();
    }

}
